﻿#region

using System;
using FluentRibbon;
using FluentRibbon.Definitions;
using FluentRibbon.Definitions.Controls;
using FluentRibbon.Libraries;
using Microsoft.SharePoint;
using SpWiki.Layouts.SpWiki.Forms;

#endregion

namespace SpWiki.EventReceivers.SpWikiDocumentLibraryEventReceiver
{
    /// <summary>
    /// List Events
    /// </summary>
    public class SpWikiDocumentLibraryEventReceiver : SPListEventReceiver
    {
        private Guid ReceiverGuid
        {
            get { return new Guid("600B36AE-C1AF-4F42-A5B7-5C2A2C239C8E"); }
        }

        /// <summary>
        /// A list is being added.
        /// </summary>
        public override void ListAdding(SPListEventProperties properties)
        {
            base.ListAdding(properties);
        }

        /// <summary>
        /// A list is being deleted.
        /// </summary>
        public override void ListDeleting(SPListEventProperties properties)
        {
            base.ListDeleting(properties);
        }

        /// <summary>
        /// A list was added.
        /// </summary>
        public override void ListAdded(SPListEventProperties properties)
        {

         }

        /// <summary>
        /// A list was deleted.
        /// </summary>
        public override void ListDeleted(SPListEventProperties properties)
        {
            base.ListDeleted(properties);
        }

        private void AddRibbonBarGroup(SPListEventProperties properties)
        {
            var group = GetGroupDefinition();
            var ribbonCustomAction = new RibbonCustomAction();
            ribbonCustomAction.AddControlGroup(group, SPRibbonIds.ListItem.Id, 25);
            ribbonCustomAction.Provision(ReceiverGuid, properties.List);
        }

        private GroupDefinition GetGroupDefinition()
        {
            return new
                GroupDefinition
                       {
                           Id = "a",
                           Title = "a",
                           Template = GroupTemplateLibrary.SimpleTemplate,
                           Controls = new
                               ControlDefinition[]
                                          {
                                              new
                                                  ButtonDefinition
                                                  {
                                                      Id = Ribbon.ButtonViewId,
                                                      Title = Ribbon.ButtonViewTitle,
                                                      CommandJavaScript =
                                                          "NavigateToUrl('aaa');",
                                                      Image =
                                                          ImageLibrary.GetStandardImage(2, 14)
                                                  },
                                              new
                                                  ButtonDefinition
                                                  {
                                                      Id = Ribbon.ButtonEditId,
                                                      Title = Ribbon.ButtonEditTitle,
                                                      CommandJavaScript =
                                                          "NavigateToUrl('bbb');",
                                                      Image =
                                                          ImageLibrary.GetStandardImage(3, 5),
                                                  }
                                          }
                       };
        }
    }
}